/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import Entity.BaoCaoTonKho;
import Util.DatabaseHandle;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Dark_Knight
 */
public class BaoCaoTonKhoImpl implements BaoCaoTonKhoDAO {

    public boolean add(BaoCaoTonKho data) {
        String sql = "{ call sp_BAOCAOTONKHO_add(?,?,?)}";
        DatabaseHandle db = new DatabaseHandle(sql, true);
        
        try {
            db.setOutParameter(1, java.sql.Types.INTEGER);
            db.setParameter(2, data.getThang());
            db.setParameter(3, data.getNam());
            
            db.executeStorePro();
            
            data.setMaBaoCaoTonKho(db.getIntOutValue(1));
            db.closed();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(BaoCaoTonKhoImpl.class.getName()).log(Level.SEVERE, null, ex);
            db.closed();
            return false;
        }
        
    }

    public boolean delete(int MaBaoCaoTon) {
        String sql = "{ call sp_BAOCAOTONKHO_delete(?) }";
        DatabaseHandle db = new DatabaseHandle(sql, true);
        
        try {
            
            db.setParameter(1, MaBaoCaoTon);
            db.executeStorePro();
            db.closed();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(BaoCaoTonKhoImpl.class.getName()).log(Level.SEVERE, null, ex);
            db.closed();
            return false;
        }
    }

    public boolean edit(BaoCaoTonKho data) {
        String sql = "{ call sp_BAOCAOTONKHO_edit(?,?,?)}";
        DatabaseHandle db = new DatabaseHandle(sql, true);
        
        try {
            db.setParameter(1, data.getMaBaoCaoTonKho());
            db.setParameter(2, data.getThang());
            db.setParameter(3, data.getNam());
            
            db.executeStorePro();
            db.closed();
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(BaoCaoTonKhoImpl.class.getName()).log(Level.SEVERE, null, ex);
            db.closed();
            return false;
        }
    }
    
}
